package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowedOperation implements IOperation{
    public void work(BookList bookList){
        System.out.println("借阅书籍！");

        int currentSize = bookList.getUsedSize();

        System.out.println("请输入你要借的书：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBooks(i);
            if (book.getName().equals(name)){
                if (!book.isBorrowed()){
                    book.setBorrowed(true);
                    System.out.println("借阅成功");
                }else {
                    System.out.println("要的书已经被借走了");
                }
                return;
            }
        }
        System.out.println("没有你要借阅的书");
    }
}
